/* icintr.p - COMMON PROGRAM FOR MISC INVENTORY TRANSACTIONS                  */
/* Copyright 1986 QAD Inc. All rights reserved.                               */
/* $Id:: icintr.p 86383 2019-06-20 02:12:29Z zzh                           $: */
/* REVISION: 2.1      LAST MODIFIED: 10/01/87   BY: wug                       */
/* REVISION: 6.0      LAST MODIFIED: 04/03/90   BY: wug *D015*                */
/* REVISION: 6.0      LAST MODIFIED: 04/09/90   BY: wug *D002*                */
/* REVISION: 6.0      LAST MODIFIED: 07/30/90   BY: ram *D030*                */
/* REVISION: 6.0      LAST MODIFIED: 12/17/90   BY: wug *D619*                */
/* REVISION: 6.0      LAST MODIFIED: 04/23/91   BY: wug *D569*                */
/* REVISION: 6.0      LAST MODIFIED: 04/23/91   BY: wug *D575*                */
/* REVISION: 6.0      LAST MODIFIED: 08/01/91   BY: emb *D800*                */
/* REVISION: 7.0      LAST MODIFIED: 09/18/91   BY: pma *F003*                */
/* REVISION: 6.0      LAST MODIFIED: 11/08/91   BY: wug *D920*                */
/* REVISION: 6.0      LAST MODIFIED: 11/11/91   BY: wug *D887*                */
/* REVISION: 7.0      LAST MODIFIED: 02/12/92   BY: pma *F190*                */
/* REVISION: 7.0      LAST MODIFIED: 05/22/92   BY: pma *F522*                */
/* REVISION: 7.0      LAST MODIFIED: 05/27/92   BY: emb *F541*                */
/* REVISION: 7.0      LAST MODIFIED: 05/27/92   BY: jjs *F681*                */
/* REVISION: 7.0      LAST MODIFIED: 07/07/92   BY: pma *F735*                */
/* REVISION: 7.0      LAST MODIFIED: 07/16/92   BY: pma *F772*                */
/* REVISION: 7.3      LAST MODIFIED: 10/02/92   BY: mpp *G011*                */
/* REVISION: 7.3      LAST MODIFIED: 11/03/92   BY: rwl *G264*                */
/* REVISION: 7.3      LAST MODIFIED: 11/30/92   BY: pma *G366*                */
/* REVISION: 7.3      LAST MODIFIED: 03/20/93   BY: pma *G852*                */
/* REVISION: 7.3      LAST MODIFIED: 03/31/93   BY: ram *G886*                */
/* REVISION: 7.4      LAST MODIFIED: 07/22/93   BY: pcd *H039*                */
/* REVISION: 7.4      LAST MODIFIED: 09/01/93   BY: dpm *H075*                */
/* REVISION: 7.4      LAST MODIFIED: 09/11/94   BY: rmh *GM10*                */
/* REVISION: 7.4      LAST MODIFIED: 09/12/94   BY: ljm *GM02*                */
/* REVISION: 7.4      LAST MODIFIED: 10/11/94   BY: dpm *GN25*                */
/* REVISION: 7.4      LAST MODIFIED: 11/06/94   by: rwl *GO25*                */
/* REVISION: 8.5      LAST MODIFIED: 12/09/94   BY: taf *J038*                */
/* REVISION: 8.5      LAST MODIFIED: 12/21/94   BY: ktn *J041*                */
/* REVISION: 7.4      LAST MODIFIED: 12/22/94   by: pxd *F0BK*                */
/* REVISION: 7.4      LAST MODIFIED: 03/09/95   by: pxd *F0LZ*                */
/* REVISION: 8.5      LAST MODIFIED: 05/17/95   BY: sxb *J04D*                */
/* REVISION: 8.5      LAST MODIFIED: 06/16/95   by: rmh *J04R*                */
/* REVISION: 7.4      LAST MODIFIED: 07/13/95   by: dzs *G0S3*                */
/* REVISION: 7.3      LAST MODIFIED: 11/01/95   BY: ais *G0V9*                */
/* REVISION: 8.5      LAST MODIFIED: 03/05/96   BY: sxb *J053*                */
/* REVISION: 8.5      LAST MODIFIED: 05/01/96   BY: jym *G1MN*                */
/* REVISION: 8.5      LAST MODIFIED: 05/13/96   BY: *G1VC* Julie Milligan     */
/* REVISION: 8.6      LAST MODIFIED: 10/19/96   BY: *K003* Vinay Nayak-Sujir  */
/* REVISION: 8.6      LAST MODIFIED: 12/06/96   BY: *K030* Vinay Nayak-Sujir  */
/* REVISION: 8.6      LAST MODIFIED: 12/30/96   BY: *J1CZ* Russ Witt          */
/* REVISION: 8.6      LAST MODIFIED: 01/27/97   BY: *H0QP* Julie Milligan     */
/* REVISION: 8.6      LAST MODIFIED: 04/15/96   BY: *K08N* Vinay Nayak-Sujir  */
/* REVISION: 8.6      LAST MODIFIED: 12/22/97   BY: *H1HN* Jean Miller        */
/* REVISION: 8.6E     LAST MODIFIED: 02/23/98   BY: *L007* A. Rahane          */
/* REVISION: 8.6E     LAST MODIFIED: 05/20/98   BY: *K1Q4* Alfred Tan         */
/* REVISION: 8.6E     LAST MODIFIED: 10/04/98   BY: *J314* Alfred Tan         */
/* REVISION: 9.1      LAST MODIFIED: 10/01/99   BY: *N014* Murali Ayyagari    */
/* REVISION: 9.1      LAST MODIFIED: 03/24/00   BY: *N08T* Annasaheb Rahane   */
/* REVISION: 9.1      LAST MODIFIED: 03/26/00   BY: *N0DJ* Rajinder Kamra     */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KS* Mark Brown         */
/* Old ECO marker removed, but no ECO header exists *F0PN*                    */
/* REVISION: 9.1      LAST MODIFIED: 09/27/00   BY: *N0W6* Mudit Mehta        */
/* Revision: 1.20        BY: Niranjan R.         DATE: 07/12/01  ECO: *P00L*  */
/* Revision: 1.22        BY: Niranjan R.         DATE: 07/12/01  ECO: *P019*  */
/* Revision: 1.23        BY: Niranjan R.         DATE: 07/31/01  ECO: *P01B*  */
/* Revision: 1.24        BY: Niranjan R.         DATE: 08/31/01  ECO: *P01X*  */
/* Revision: 1.26        BY: Ellen Borden        DATE: 10/24/01  ECO: *P00G*  */
/* Revision: 1.27        BY: Samir Bavkar        DATE: 04/05/02  ECO: *P000*  */
/* Revision: 1.32        BY: Jean Miller         DATE: 05/15/02  ECO: *P05V*  */
/* Revision: 1.34        BY: Steve Nugent        DATE: 06/10/02  ECO: *P07Y*  */
/* Revision: 1.35        BY: Ashish Maheshwari   DATE: 07/17/02  ECO: *N1GJ*  */
/* Revision: 1.36        BY: Vinod Nair          DATE: 10/03/02  ECO: *N1WB*  */
/* Revision: 1.37        BY: Dorota Hohol        DATE: 02/25/03  ECO: *P0N6*  */
/* Revision: 1.39        BY: K Paneesh           DATE: 03/20/03  ECO: *P0NZ*  */
/* Revision: 1.40        BY: Manisha Sawant      DATE: 05/05/03  ECO: *N2F1*  */
/* Revision: 1.42        BY: Paul Donnelly (SB)  DATE: 06/26/03  ECO: *Q00G*  */
/* Revision: 1.44        BY: Jean Miller         DATE: 08/22/03  ECO: *P10J*  */
/* Revision: 1.45        BY: Dorota Hohol        DATE: 10/02/03  ECO: *P112*  */
/* Revision: 1.46        BY: Russ Witt           DATE: 06/21/04  ECO: *P1CZ*  */
/* Revision: 1.47        BY: Paul Dreslinski     DATE: 10/28/04  ECO: *M1LL*  */
/* Revision: 1.48        BY: Ed van de Gevel     DATE: 18/03/05  ECO: *R00F*  */
/* Revision: 1.51        BY: Andrew Dedman       DATE: 09/29/05  ECO: *R021*  */
/* Revision: 1.52        BY: Shilpa Kamath       DATE: 04/18/06  ECO: *R03R*  */
/* Revision: 1.53        BY: Shilpa Kamath       DATE: 06/04/06  ECO: *R05V* */
/* Revision: 1.54        BY: Shilpa Kamath       DATE: 06/19/06  ECO: *R06J* */
/* Revision: 1.55        BY: Dilip Manawat       DATE: 08/04/06  ECO: *P4ZK* */
/* Revision: 1.56        BY: Xavier Prat         DATE: 10/18/06  ECO: *R09Z* */
/* Revision: 1.57        BY: Munira Savai        DATE: 11/14/06  ECO: *P5F9* */
/* Revision: 1.58        BY: David Morris        DATE: 01/04/07  ECO: *R0C6* */
/* Revision: 1.59        BY: Katie Hilbert       DATE: 03/17/08  ECO: *R0PT* */
/* Revision: 1.60        BY: Neil Curzon         DATE: 03/10/08  ECO: *R0P6* */
/* Revision: 1.61        BY: Jean Miller         DATE: 06/15/08  ECO: *R0V6* */
/* Revision: 1.63        BY: Avishek Chakraborty DATE: 11/18/08  ECO: *Q20F* */
/* Revision: 1.63        BY: Niranjan Ranka      DATE: 10/15/08  ECO: *R179* */
/* Revision: 1.64        BY: Sandeep Rohila      DATE: 08/10/09   ECO: *Q35K* */
/* Revision: 1.65        BY: Miguel Alonso       DATE: 05/07/10  ECO: *R204*  */
/* Revision: 1.66        BY: Yiqing Chen         DATE: 04/12/10   ECO: *R1Z0* */
/* Revision: 1.67        BY: Miguel Alonso       DATE: 07/21/10   ECO: *R23C* */
/*-Revision end---------------------------------------------------------------*/
/******************************************************************************/
/* All patch markers and commented out code have been removed from the source */
/* code below. For all future modifications to this file, any code which is   */
/* no longer required should be deleted and no in-line patch markers should   */
/* be added.  The ECO marker should only be included in the Revision History. */
/******************************************************************************/
 
/* Type of transaction:  "RCT-UNP" (unplanned receipts)                       */
/*                       "RCT-SOR" (s.o. returns)                             */
/*                       "RCT-RS"  (return to stock)                          */
/*                       "RCT-WO"  (unplanned receipts backward exploded)     */
/*                       "ISS-UNP" (unplanned isue)                           */
/*                       "ISS-RV"  (return to vendor)                         */
/*                       "ISS-PRV" (PO rtn to vendor)                         */

/* ADD CIP LOGICAL BY GAOYAN DATE:11/10/23      ECO:GY01                      */

using com.qad.eefin.bdomain.DomainForOperationalInfo.
using com.qad.eefin.bexchangeratetype.ExchangeRateTypeByTypeCode.
using com.qad.eefin.bcurrency.SelectCurrency.
 
/* DISPLAY TITLE */
{us/mf/mfdtitle.i}
{us/gp/gpuid.i}
{us/mf/mfaititl.i} /* SUPPRESS DISPLAY OF SCREEN TITLE IN API MODE */
{us/px/pxmaint.i}
{us/px/pxphdef.i gpumxr}
{us/px/pxphdef.i ppitxr}
{us/px/pxphdef.i fssmxr}
{us/px/pxphdef.i pafunc}
{us/px/pxphdef.i paicxr}
{us/px/pxphdef.i icintrxr}
{us/px/pxphdef.i caatdxr}
{us/px/pxphdef.i caisxr}
{us/px/pxphdef.i soldxr}
{us/px/pxphdef.i carcxr}
{us/px/pxphdef.i caparaxr}
{us/px/pxphdef.i captdxr2}
{us/px/pxphdef.i caexatxr}
{us/px/pxphdef.i gpldxr}
/* PROGRAM X-REFERENCE FUNCTIONS */
{us/wh/whexecfn.i}
 
{us/pa/pattintr.i}
{us/ca/caattr.i}
{us/ca/cattdef2.i}
 
define new shared variable yn                  like mfc_logical.
define new shared variable part                like tr_part.
define new shared variable um                  like pt_um no-undo.
define new shared variable conv                like um_conv
                                               label "Conversion" no-undo.
define new shared variable ref                 like glt_ref.
define new shared variable eff_date            like glt_effdate
                                               label "Effective".
define new shared variable trlot               like tr_lot.
define new shared variable qty_loc             like tr_qty_loc.
define new shared variable qty_loc_label       as character format "x(12)".
define new shared variable issrct              as character format "x(3)".
define new shared variable issuereceipt        as character format "x(7)".
define new shared variable unit_cost           like tr_price
                                               label "Unit Cost".
define new shared variable total_amt           like tr_gl_amt
                                               label "Total Cost".
define new shared variable ordernbr            like tr_nbr.
define new shared variable orderline           like tr_line.
define new shared variable so_job              like tr_so_job.
define new shared variable traddr              like tr_addr.
define new shared variable rmks                like tr_rmks.
define new shared variable serial              like tr_serial.
define new shared variable dr_acct             like trgl_dr_acct.
define new shared variable dr_sub              like trgl_dr_sub.
define new shared variable dr_cc               like trgl_dr_cc.
define new shared variable cr_acct             like trgl_cr_acct.
define new shared variable cr_sub              like trgl_cr_sub.
define new shared variable cr_cc               like trgl_cr_cc.
define new shared variable trqty               like tr_qty_loc.
define new shared variable i                   as integer.
define new shared variable tot_units           as character format "x(16)".
define new shared variable del-yn              like mfc_logical initial no.
define new shared variable null_ch             as character initial "".
define new shared variable reject_qty_label    as character format "x(11)".
define new shared variable qty_reject          like tr_qty_loc.
define new shared variable qty_iss_rcv         like qty_loc.
define new shared variable pt_recid            as recid.
define new shared variable project   like wo_proj no-undo.
define new shared variable multi_entry         like mfc_logical
                                               label "Multi Entry" no-undo.
define new shared variable lotserial_control   as character.
define new shared variable cline               as character.
define new shared variable issue_or_receipt    as character.
define new shared variable site                like sr_site no-undo.
define new shared variable location            like sr_loc no-undo.
define new shared variable lotserial           like sr_lotser no-undo.
define new shared variable lotserial_qty       like sr_qty no-undo.
define new shared variable total_lotserial_qty like sr_qty
                                               label "Total Qty".
define new shared variable trans_um            like pt_um.
define new shared variable trans_conv          like sod_um_conv.
define new shared variable lotref              like sr_ref format "x(8)" no-undo.
define new shared variable tr_recno            as recid.
 
define new shared variable lgdkey  as decimal no-undo.
define new shared variable issueld as logical no-undo.
 
define variable errorFound as logical    no-undo.
define variable msgLevel   as integer    no-undo.
define variable msgNum     as integer    no-undo.
 
define shared variable transtype as character format "x(7)".
 
define variable l_create_shipper as logical initial yes  no-undo.
define variable lotum as character.
define variable dr_desc like ac_desc format "x(23)".
define variable cr_desc like ac_desc format "x(23)".
define variable dr_proj like wo_proj.
define variable cr_proj like wo_proj.
 
define variable valid_acct  like mfc_logical.
define variable undo-input  like mfc_logical.
define variable lotnext     like wo_lot_next .
define variable lotprcpt    like wo_lot_rcpt no-undo.
define variable error-found like mfc_logical.
define variable total_amt_fmt as character.
define variable shipnbr     like tr_ship_id no-undo.
define variable inv_mov     like tr_ship_inv_mov no-undo.
define variable ship_date   like tr_ship_date no-undo.
define variable gl-site     like in_site   no-undo.
define variable gl-set      like in_gl_set no-undo.
 
define variable dftPURAcct       like pl_pur_acct no-undo.
define variable dftPURSubAcct    like pl_pur_sub  no-undo.
define variable dftPURCostCenter like pl_pur_cc   no-undo.
define variable dftFLRAcct       like pl_flr_acct no-undo.
define variable dftFLRSubAcct    like pl_flr_sub  no-undo.
define variable dftFLRCostCenter like pl_flr_cc   no-undo.
define variable dftCOPAcct       like pl_cop_acct no-undo.
define variable dftCOPSubAcct    like pl_cop_sub  no-undo.
define variable dftCOPCostCenter like pl_cop_cc   no-undo.
 
define variable l_acct           like pl_pur_acct no-undo.
define variable l_sub            like pl_pur_sub  no-undo.
define variable l_cc             like pl_pur_cc   no-undo.
 
define variable l_unp_acct       like mfc_logical no-undo.
define variable isSerialized     like mfc_logical no-undo.
define variable validationPass      as character format "x(14)" no-undo.
define variable allowToIssue     as logical  no-undo.
define variable toWarning as logical no-undo.
define variable looseQty like sr_qty no-undo.
define new shared variable lLegacyAPI      as   logical     no-undo.
/* CONSIGNMENT VARIABLES. */
{us/so/socnvars.i}
 
define variable consigned_line               like mfc_logical              no-undo.
define variable l_oldLoc                     like sr_loc                   no-undo.                                                                
define variable DomainInfo                   as DomainForOperationalInfo   no-undo.
define variable ExchangeRateType             as ExchangeRateTypeByTypeCode no-undo.
define variable StatCurrency                 as SelectCurrency             no-undo.
define variable l_glx_set                    as character                  no-undo.
define variable l_glx_mthd                   as character                  no-undo.
define variable l_cur_set                    as character                  no-undo.
define variable l_cur_mthd                   as character                  no-undo.
define variable l_mgmt_curr_ex_rate1         as decimal                    no-undo.
define variable l_mgmt_curr_ex_rate2         as decimal                    no-undo.
define variable l_mgmt_acct_ex_rate1         as decimal                    no-undo.
define variable l_mgmt_acct_ex_rate2         as decimal                    no-undo.
define variable l_lStatCurrError             as logical                    no-undo.
define variable l_iStatErrorMsg              as integer                    no-undo.
define variable l_using_supplier_consignment as logical                    no-undo.
define variable serialized_qty               as decimal                    no-undo.
define variable cCompanyList                 as character                  no-undo. 
define variable l_effdt                      like mfc_logical initial no   no-undo.

define variable cipid                        as character   format "x(20)" no-undo.    /* GY01 */
define variable cipdesc                      as character   format "x(20)" no-undo.    /* GY01 */
 
/* COMMON API CONSTANTS AND VARIABLES */
{us/mf/mfaimfg.i}
/* INVENTORY CONTROL API TEMP-TABLE */
{us/ic/icicit01.i}
/* INVENTORY CONTROL API2.0 DATASET DEF */
{us/ic/icdsicit.i "reference-only"}
 
{us/gp/gpglefv.i}
{us/gp/gprunpdf.i "gpglvpl" "p"}
 
{us/up/updaterestriction.i}
 
{us/gp/gpldform.i}
{us/gp/gpscdef.i}
{us/gp/gpscproxy.i}
for first poc_ctrl no-lock
   where poc_domain = global_domain:
end.
 
run mfairunh.p (input "mgurpl.p",
                input ?,
                output hUpdateRestrictedLibrary).
 
if c-application-mode = "API" then do:
   /* Get handle of API 2.0 Controller */
   {us/bbi/gprun.i ""gpaigach.p"" "(output ApiMethodHandle)"}
 
   if valid-handle(ApiMethodHandle) then do:
      run getRequestDataset in ApiMethodHandle(output dataset dsInvTrans bind).
      lLegacyAPI = false.

      /* Allow API to call attribute code */
      {us/px/pxrun.i &PROC       = 'allowApiCall'
                     &PROGRAM    = 'caexatxr.p'
                     &HANDLE     = ph_caexatxr
                     &NOAPPERROR = true
                     &CATCHERROR = true
      }
   end.
   else do:
      /* GET HANDLE OF API CONTROLLER */
      {us/bbi/gprun.i ""gpaigh.p""
               "(output apiMethodHandle,
                 output apiProgramName,
                 output apiMethodName,
                 output apiContextString)"}
 
      /* GET TRANSACTION DETAIL TEMP-TABLE */
      run getInventoryTransDet in apiMethodHandle
         (output table ttInventoryTransDet).
 
      /* GET TRANSACTION RECORD FROM TEMP-TABLE
       * (ONLY THE FIRST RECORD IS PROCESSED)
       */
      run getInventoryTransRecord in apiMethodHandle
         (buffer ttInventoryTrans).
      assign
         transtype   = ttInventoryTrans.transType
         lLegacyAPI  = true.
   end.
end. /* IF c-application-mode = "API" */
 
form
   pt_part             colon 17
   pt_lot_ser          colon 57
   pt_um
   pt_desc1            colon 17
   pt_desc2            at 19    no-label
   lotserial_qty       colon 17
   site                colon 57
   um                  colon 17
   location            colon 57
   conv                colon 17
   lotserial           colon 57
   lotref              colon 57
   multi_entry         colon 57
   unit_cost           colon 17
   total_lotserial_qty colon 57 format "->>>,>>>,>>9.9<<<<<<<<<"
   ordernbr            colon 17
   total_amt           colon 57
   orderline           colon 17
   so_job              colon 17
   traddr              colon 17
   rmks                colon 17 format "x(24)"
   eff_date            colon 17
   dr_acct             colon 17
   dr_sub                       no-label
   dr_cc                        no-label
   dr_proj                      no-label
   dr_desc                      no-label
   cr_acct             colon 17
   cr_sub                       no-label
   cr_cc                        no-label
   cr_proj                      no-label
   cr_desc                      no-label
with frame a side-labels width 80.
 
/* SET EXTERNAL LABELS */
setFrameLabels(frame a:handle).
 
 
/* GY01 CIP SCREEN FORM */ 
form
   cipid colon 25
   cipdesc  colon 25
   space(2)
with frame cip row 8 centered overlay side-labels.
 
/* SET EXTERNAL LABELS */
setFrameLabels(frame cip:handle).
 
if transtype = "ISS-RV" then do:
   if can-find(first po_mstr
               where po_domain = global_domain and
                     po_nbr >= "")
   then do:
      /* Use PO RTS Issue */
      {us/bbi/pxmsg.i &MSGNUM=350 &ERRORLEVEL=2}
      if not batchrun then
         pause.
      leave.
   end.
end.
 
issrct = substring(transtype,1,3).
 
if issrct = "RCT" then
   issue_or_receipt = getTermLabel("RECEIPT",8).
else
   issue_or_receipt = getTermLabel("ISSUE",8).
 
assign
   lotnext = ""
   lotprcpt = no.
 
{us/bbi/gprun.i ""socrshc.p""}
find first shc_ctrl where shc_domain = global_domain no-lock.
/* DETERMINE IF SUPPLIER CONSIGNMENT IS ACTIVE */
{us/bbi/gprun.i ""gpmfc01.p""
                "(input  'enable_supplier_consignment',
                  input  11,
                  input  ADG,
                  input  'cns_ctrl',
                  output l_using_supplier_consignment)"}
define variable oidDosrDet like oid_dosr_det no-undo.
define variable restockingDone as logical no-undo.
run defaultDepotOrderRestock.
 
subscribe to "itemAttributeUIPrompt" anywhere.
 
for first lgdc_ctrl no-lock
   where lgdc_ctrl.lgdc_domain = global_domain
   and   lgdc_ctrl.lgdc_type   = "ISS":
   if lgdc_ctrl.lgdc_eff_date then                                  
      l_effdt = yes.
end.
if not available lgdc_ctrl then
   l_effdt = yes.
   
mainloop:
repeat:

   skipblock:
   do:

      updateblock:
      do on stop undo, leave:

         /* DO NOT RETRY WHEN PROCESSING API REQUEST */
         if retry and c-application-mode = "API"
            then return error return-value.
       
         if c-application-mode = "API" and not lLegacyAPI then do:
            run getNextRecord in ApiMethodHandle (input "ttInvTrans").
            if return-value = {&RECORD-NOT-FOUND} then do:
               leave mainloop.
            end.
         end. /* if c-application-mode = "API" */
       
         do transaction:
       
            for each sr_wkfl where sr_domain = global_domain and
                                   sr_userid = SessionUniqueID
            exclusive-lock:
               delete sr_wkfl.
            end.
       
            {us/bbi/gprun.i ""gplotwdl.p""}
       
            empty temp-table tt_attr_pfvalue.
       
         end.
       
         /* DO NOT ACCESS UI WHEN PROCESSING API REQUEST */
         if c-application-mode <> "API" then do:
            prompt-for pt_part with frame a no-validate
            editing:
       
               /* FIND NEXT/PREVIOUS RECORD */
               {us/mf/mfnp.i pt_mstr pt_part  "pt_domain = global_domain and pt_part"
               
                       pt_part pt_part pt_part}
       
               if recno <> ? then
                  display
                     pt_part
                     pt_desc1
                     pt_um
                     pt_lot_ser
                     pt_desc2
                  with frame a.
       
            end. /* END editing */
         status input.
       
       
            end.
         else
            if not lLegacyAPI then
               assign
                  {us/mf/mfaiprvl.i pt_part ttInvTrans.ptPart}.
       
         if c-application-mode <> "API" then
            status input.
       
         /* DO NOT ACCESS UI WHEN PROCESSING API REQUEST */
         if c-application-mode = "API" then
            assign
               total_lotserial_qty = 0
               total_amt = 0.
         else
            display
               "" @ total_lotserial_qty
               "" @ total_amt
            with frame a.
       
         if c-application-mode = "API" and lLegacyAPI then
               find pt_mstr where pt_domain = global_domain and
                                pt_part = ttInventoryTrans.part
               no-lock no-error.
         else
         find pt_mstr where pt_domain = global_domain and
                            pt_part   = input pt_part
         no-lock no-error.
         if not available pt_mstr then do:
            /* Item is not available */
            {us/bbi/pxmsg.i &MSGNUM=16 &ERRORLEVEL=3}
            undo, retry.
         end.
       
         {us/px/pxrun.i &PROC  = 'isItemSerializationMandatory'
                           &PROGRAM = 'pafunc.p'
                           &HANDLE = ph_pafunc
                           &PARAM = "( input  pt_part,
                                       output isSerialized)"
                           &NOAPPERROR = true
                           &CATCHERROR = true}
       
         if transtype = "RCT-UNP" then do:
            if isSerialized then do:
               /* Please use "Pack Receipt Unplanned" for this transaction */
               {us/bbi/pxmsg.i &MSGNUM=11476 &ERRORLEVEL=3}
               undo, retry.
            end.
         end.
         else if transType = "ISS-UNP" then do:
            if isSerialized then do:
               /* Please use "Pack Issue Unplanned" for this transaction */
               {us/bbi/pxmsg.i &MSGNUM=13411 &ERRORLEVEL=3}
               undo, retry.
            end.
         end.
       
         if transtype = "RCT-SOR" or
            transtype = "RCT-RS" then do:
            {us/px/pxrun.i &PROC  = 'isItemSerializationMandatory'
                           &PROGRAM = 'pafunc.p'
                           &HANDLE = ph_pafunc
                           &PARAM = "( input  pt_part,
                                       output isSerialized)"
                           &NOAPPERROR = true
                           &CATCHERROR = true}
            if isSerialized then do:
               /* Serialized Item is not allowed */
               {us/bbi/pxmsg.i &MSGNUM=13694 &ERRORLEVEL=3}
               undo, retry.
            end.
         end.
       
         assign
            pt_recid = recid(pt_mstr)
            um = pt_um
            conv = 1.
       
         if eff_date = ? then eff_date = today.
       
         find pl_mstr where pl_domain    = global_domain and
                            pl_prod_line = pt_prod_line
         no-lock.
       
         do transaction:
            /* GET NEXT LOT */
            {us/mf/mfnxtsq.i  "wo_domain = global_domain and "
                        wo_mstr wo_lot woc_sq01 trlot}
         end.
       
         /* SET GLOBAL PART VARIABLE */
         assign
            global_part = pt_part
            part = pt_part
            um = pt_um
            conv = 1
            l_create_shipper = yes.
       
         /* DO NOT ACCESS UI WHEN PROCESSING API REQUEST */
         if c-application-mode <> "API" then
            display
               pt_part
               pt_lot_ser
               pt_um
               pt_desc1
               pt_desc2
               um
               conv
            with frame a.
       
         assign
            total_lotserial_qty = 0
            lotserial_control = pt_lot_ser.

         {us/px/pxrun.i &PROC  = 'clearGetFieldDefaultTempRecord'
                        &PROGRAM = 'ppitxr.p'
                        &HANDLE  = ph_ppitxr
                        &PARAM   = "(input  pt_part,
                                     input  pt_site)"
                        &NOAPPERROR = true
                        &CATCHERROR = true}
       
         {us/px/pxrun.i &PROC  = 'getFieldDefault' &PROGRAM = 'ppitxr.p'
                  &HANDLE = ph_ppitxr
                  &PARAM = "( input  pt_part,
                              input  pt_site,
                              input ""pt_lot_ser"",
                              output lotserial_control)"
                  &NOAPPERROR = true
                  &CATCHERROR = true}
       
         setd:
         repeat on endkey undo mainloop, retry mainloop:
       
            if c-application-mode = "API" and not lLegacyAPI and retry then
               next mainloop.
       
            assign
               dr_proj   = ""
               cr_proj   = ""
               site      = if oidDosrDet = 0 then "" else site
               location  = if oidDosrDet = 0 then "" else location
               lotserial = if oidDosrDet = 0 then "" else lotserial
               lotref    = ""
               lotserial_qty = if oidDosrDet = 0 then total_lotserial_qty
                                                 else lotserial_qty
               cline     = ""
               global_part = pt_part
               i = 0.
       
            for each sr_wkfl where sr_domain = global_domain
                               and sr_userid = SessionUniqueID
                               and sr_lineid = cline
            no-lock:
               i = i + 1.
               if i > 1 then leave.
            end.
       
            if oidDosrDet = 0 then
               if i = 0 and available pt_mstr then do:
                  assign
                     site     = pt_site
                     location = pt_loc.

                  {us/px/pxrun.i &PROC  = 'getFieldDefault' 
                           &PROGRAM = 'ppitxr.p'
                           &HANDLE = ph_ppitxr
                           &PARAM = "(input  global_part,
                                      input  site,
                                      input ""pt_loc"",
                                      output location)"
                           &NOAPPERROR = true
                           &CATCHERROR = true}
               end.
               else
                  if i = 1 then do:
                     find first sr_wkfl where sr_domain = global_domain
                                          and sr_userid = SessionUniqueID
                                          and sr_lineid = cline
                     no-lock.
                     site      = sr_site.
                     location  = sr_loc.
                     lotserial = sr_lotser.
                     lotref    = sr_ref.
                  end.
       
            do on error undo, retry on endkey undo mainloop, retry mainloop:
       
               /* DO NOT RETRY WHEN PROCESSING API REQUEST */
               if retry and c-application-mode = "API"
                  then return error return-value.
               /* DO NOT ACCESS UI WHEN PROCESSING API REQUEST */
               if c-application-mode = "API" then do:
                  if lLegacyAPI then do:
                     /*
                     * SUM TOTAL QUANTITY FROM LOT/SERIAL DETAIL
                     */
                     ACCUM-LOOP:
                     for each ttInventoryTransDet no-lock:
                        accumulate ttInventoryTransDet.qty (count).
                        if (Accum count ttInventoryTransDet.qty) > 1
                        then do:
                           multi_entry = yes.
                           leave ACCUM-LOOP.
                        end.
                     end.
                     find first ttInventoryTransDet
                        no-lock no-error.
                     if not available ttInventoryTransDet then do:
                        /* INVALID DATA PASSED */
                        {us/bbi/pxmsg.i &MSGNUM=1960 &ERRORLEVEL=4}
                     end.
                     else assign
                        {us/mf/mfaiset.i lotserial_qty ttInventoryTransDet.qty}
                        {us/mf/mfaiset.i um ttInventoryTrans.um}
                        {us/mf/mfaiset.i conv ttInventoryTrans.conv}
                        {us/mf/mfaiset.i site ttInventoryTransDet.site}
                        {us/mf/mfaiset.i location ttInventoryTransDet.loc}
                        {us/mf/mfaiset.i lotserial ttInventoryTransDet.lotSer}
                        {us/mf/mfaiset.i lotref ttInventoryTransDet.ref}
                        {us/mf/mfaiset.i multi_entry 
                                         ttInventoryTrans.multi_entry}
                         .
                     /*
                      * SET CURRENT POSITION TO FIRST RECORD FOR
                      * SUB-PROGRAM ACCESS
                      */
                     run setInventoryTransDetRow
                        in apiMethodHandle (input ?).
                  end.
                  else do:
                     if ttInvTrans.lotSerialQty <> ?
                     then
                        lotserial_qty = ttInvTrans.lotSerialQty.
                     else
                        assign {us/mf/mfaistvl.i lotserial_qty ttInvTrans.lotSerialQty}.

                     assign
                        {us/mf/mfaistvl.i um ttInvTrans.um}
                        {us/mf/mfaistvl.i conv ttInvTrans.conv}
                        {us/mf/mfaistvl.i site ttInvTrans.site}
                        {us/mf/mfaistvl.i location ttInvTrans.location}
                        {us/mf/mfaistvl.i lotserial ttInvTrans.lotSerial}
                        {us/mf/mfaiset.i  lotref ttInvTrans.lotRef}
                        {us/mf/mfaistvl.i multi_entry ttInvTrans.multiEntry}
                        global_site = input site
                        global_loc  = input location
                        global_lot  = input lotserial.
                  end.     /* else do */
               end. /* IF c-application-mode = "API" */
       
               else do: /* IF c-application-mode <> "API" */
                  if     {us/wh/whgpwhon.i}
                     and {us/bbi/gpiswrap.i}
                  then do:
                     update
                        lotserial_qty
                        um
                        conv
                        site
                        location
                        lotserial
                        lotref
                     with frame a
                     editing:
                        global_site = input site.
                        global_loc  = input location.
                        global_lot  = input lotserial.
                        recno = ?.
                        readkey.
                        apply lastkey.

                     end.
                     set
                        multi_entry
                     with frame a.
                  end. /* IF {us/wh/whgpwhon.i} */
                  else do:
                     update
                        lotserial_qty
                        um
                        conv
                        site
                        location
                        lotserial
                        lotref
                        multi_entry
                     with frame a
                     editing:
                        global_site = input site.
                        global_loc  = input location.
                        global_lot  = input lotserial.
                        recno = ?.
                        readkey.
                        apply lastkey.
                     end.
                  end. /* ELSE DO */ 

       
                  if (transtype = "ISS-UNP" and lotserial_qty > 0)
                     or (transtype = "RCT-UNP" and lotserial_qty < 0)
                     or (transtype = "RCT-SOR" and lotserial_qty < 0)
                     or (transtype = "RCT-RS" and lotserial_qty < 0)
                  then do:
                     {us/px/pxrun.i &PROC = 'allowIssueWithoutSerialization'
                                       &PROGRAM='paicxr.p'
                                       &HANDLE = ph_paicxr
                                       &PARAM = "(input pt_part,
                                                  input site,
                                                  input location,
                                                  input lotserial,
                                                  input lotref,
                                                  input absolute(lotserial_qty),
                                                  output allowToIssue,
                                                  output looseQty)"
                                       &NOAPPERROR = true
                                       &CATCHERROR = true}
       
                     if not allowToIssue then do:
                        /* Not enough qty in inventory */
                        {us/bbi/pxmsg.i &MSGNUM=11362 
                                        &ERRORLEVEL={&APP-ERROR-RESULT}}
                        undo mainloop, retry mainloop.
                     end.
                  end.
               end. /* ELSE DO */
               {us/px/pxrun.i &PROC  = 'getFieldDefault' &PROGRAM = 'ppitxr.p'
                        &HANDLE = ph_ppitxr
                        &PARAM = "(input  global_part,
                                   input  site:screen-value,
                                   input ""pt_lot_ser"",
                                   output lotserial_control)"
                        &NOAPPERROR = true
                        &CATCHERROR = true}
       
               if um <> pt_um then do:
                  if not conv entered then do:
                     {us/px/pxrun.i &PROC  = 'retrieveUMConversion' 
                                    &PROGRAM = 'gpumxr.p'
                                    &HANDLE=ph_gpumxr
                                    &PARAM="(input pt_part,
                                             input pt_um,
                                             input um,
                                             output conv)"
                                    &NOAPPERROR=True
                                    &CATCHERROR=True}
                     if conv = ? then do:
                        /* NO UOM CONVERSION EXISTS */
                        {us/bbi/pxmsg.i &MSGNUM=33 &ERRORLEVEL=2}
                        conv = 1.
                     end.
                     /* DO NOT ACCESS UI WHEN PROCESSING API REQUEST */
                     if c-application-mode <> "API" then
                        display conv with frame a.
                  end.
               end.
       
               find in_mstr where in_domain = global_domain and
                                  in_part   = pt_part and
                                  in_site   = site
               no-lock no-error.
       
               /* GPSCT03.I LOOKS FOR IN_MSTR AND GETS THE COST, IF */
               /* IT IS NOT AVAILABLE, VALUES OF 0.00 ARE RETURNED. */
               /* IF NOT AVAIABLE,IN_MSTR IS CREATED LATER IN THIS  */
               /* PROGRAM.                                          */
               /* WITH LINKED SITE COSTING,IF THE SELECTED ITEM AND */
               /* SITE ARE LINKED TO ANOTHER SITE,I.E.IF A LINKING  */
               /* RULE EXIST FOR SELECTED SITE, THEN IN_MSTR IS     */
               /* CREATED WITH THE LINK. (I.E. IN_GL_COST SITE =    */
               /* SOURCE SITE AND IN_GL_SET = SOURCE GL COST SET.)  */
               /* THEREFORE FOR LINKED SITES THE UNIT COST RETRIEVED*/
               /* HERE SHOULD BE THE COST AT THE SOURCE SITE .      */
               /* TO AVOID CHANGING THE IN_MSTR CREATION TIMING WE  */
               /* FIND THE SOURCE SITE AND GET THE COST AT THAT SITE*/
       
               gl-site = site.
       
               if not available in_mstr then do:
                  /* SITE VALIDATION IS DONE LATER IN THE PROGRAM. WE */
                  /* NEED TO MAKE SURE si_mstr is AVAILABLE BEFORE    */
                  /* CALLING gpingl.p.                                */
                  for first si_mstr where si_domain = global_domain and
                                          si_site   = site
                  no-lock:
                     {us/bbi/gprun.i ""gpingl.p""
                              "(input  site,
                                input  pt_part,
                                output gl-site,
                                output gl-set)"}
                  end.
                  for first in_mstr where in_domain = global_domain and
                                          in_part = pt_part and
                                          in_site = gl-site
                  no-lock: end.
               end. /* IF NOT AVAILABLE IN_MSTR */
       
               if transtype = "ISS-RV" or transtype = "ISS-PRV" then do:
                  {us/gp/gpsct03.i &cost=sct_mtl_tl}
               end.
               else do:
                  {us/gp/gpsct03.i &cost=sct_cst_tot}
               end.
       
               unit_cost = glxcst.
       
               i = 0.
               for each sr_wkfl where sr_domain = global_domain and
                                      sr_userid = SessionUniqueID and
                                      sr_lineid = cline
               no-lock:
                  i = i + 1.
                  if i > 1 then do:
                     multi_entry = yes.
                     leave.
                  end.
               end.
       
               trans_um = um.
               trans_conv = conv.
       
               if multi_entry then do:
       
                  if i >= 1 then do:
                     site      = "".
                     location  = "".
                     lotserial = "".
                     lotref    = "".
                  end.
       
                  if c-application-mode = "API" and not lLegacyAPI then do:
                     run setCommonDataBuffer in ApiMethodHandle
                        (input "ttInvTransLotSer").
                  end. /* c-application-mode = "API" */
                  {us/ca/cacratpr.i}
                  /* ADDED SIXTH INPUT PARAMETER AS NO */
                  {us/bbi/gprun.i ""icsrup4.p""
                     "(input ?,
                       input """",
                       input """",
                       input-output lotnext,
                       input lotprcpt,
                       input no,
                       input table tt_attr_parameter by-reference,
                       input-output table tt_attr_pfvalue by-reference)"}
       
                  if c-application-mode = "API" and not lLegacyAPI then do:
                     run setCommonDataBuffer in ApiMethodHandle (input "").
                  end. /* c-application-mode = "API" */
       
                  for first sr_wkfl
                     where sr_domain = global_domain
                     and   sr_userid = SessionUniqueID
                     and   sr_lineid = cline
                  no-lock :
                  end. /* FOR FIRST sr_wkfl */
       
                  if not available sr_wkfl
                  then
                     undo,retry.
               end.
       
               else do:
       
                  {us/bbi/gprun.i ""paicedit.p""
                     "(transtype,
                       site,
                       location,
                       part,
                       lotserial,
                       lotref,
                       lotserial_qty * trans_conv,
                       trans_um,
                       """",
                       """",
                       toWarning,
                       output undo-input)"}
       
                  if undo-input then undo, retry.
       
                  find first sr_wkfl where sr_domain = global_domain
                                       and sr_userid = SessionUniqueID
                                       and sr_lineid = cline
                  no-error.
       
                  if lotserial_qty = 0 then do:
                     if available sr_wkfl then do:
                        total_lotserial_qty = total_lotserial_qty - sr_qty.
                        delete sr_wkfl.
                     end.
                  end.
       
                  else do:
       
                     if available sr_wkfl then do:
                        assign
                           total_lotserial_qty = total_lotserial_qty - sr_qty
                                               + lotserial_qty
                           sr_site   = site
                           sr_loc    = location
                           sr_lotser = lotserial
                           sr_ref    = lotref
                           sr_qty    = lotserial_qty.
                     end.
       
                     else do:
       
                        create sr_wkfl.
                        assign
                           sr_domain = global_domain
                           sr_userid = SessionUniqueID
                           sr_lineid = cline
                           sr_site   = site
                           sr_loc    = location
                           sr_lotser = lotserial
                           sr_ref    = lotref
                           sr_qty    = lotserial_qty.
       
                        if recid(sr_wkfl) = -1 then .
       
                        total_lotserial_qty = total_lotserial_qty 
                                            + lotserial_qty.
       
                     end.
       
                     if transtype = "ISS-UNP" and lotserial_qty > 0 then do:
                        /* Prepare temp table tt_attr_pfvalue */
                        /* which contains attributes. */
                        {us/ca/cacratpr.i}
       
                        {us/px/pxrun.i &PROC       = 'createAttrpfValueISS'
                                       &PROGRAM    = 'caisxr.p'
                                       &HANDLE     = ph_caisxr
                                       &PARAM      = "(input sr_wkfl.oid_sr_wkfl,
                                                       input pt_part,
                                                       input site,
                                                       input location,
                                                       input lotserial,
                                                       input lotref,
                                                       input transtype,
                                                       input '',
                                                       input 0,
                                                       input table tt_attr_parameter by-reference,
                                                       input-output table tt_attr_pfvalue by-reference)"
                                       &NOAPPERROR = true
                                       &CATCHERROR = true
                        }
       
                        for first tt_attr_pfvalue no-lock
                           where tt_attr_pfvalue.tt_oid_attrpf_mstr = sr_wkfl.oid_sr_wkfl
                           and tt_attr_pfvalue.tt_attrpfd_ui_display:
       
                           /* Start to maintain the attributes */
                           hide frame a no-pause.
                           {us/bbi/gprun.i ""caatui.p""
                              "(input sr_wkfl.oid_sr_wkfl,
                                input pt_part,
                                input sr_wkfl.sr_site,
                                input sr_wkfl.sr_loc,
                                input sr_wkfl.sr_lotser,
                                input sr_wkfl.sr_ref,
                                input sr_wkfl.sr_qty,
                                input trans_um,
                                input 'ISS-UNP',
                                input-output table tt_attr_pfvalue by-reference)"}
                           view frame a.
       
                        end. /* for first tt_attr_pfvalue */
       
                        /* Check Result against attribute specification */
                        {us/px/pxrun.i &PROC      ='validateAttrSpecStopOnNonConform'
                                       &PROGRAM   ='caisxr.p'
                                       &HANDLE    = ph_caisxr
                                       &PARAM     ="(input sr_wkfl.oid_sr_wkfl,
                                                     input-output table tt_attr_pfvalue by-reference)"
                                       &NOAPPERROR=true
                                       &CATCHERROR=true
                        }
       
                        if can-find(first tt_attr_pfvalue
                                        where tt_attr_pfvalue.tt_oid_attrpf_mstr = sr_wkfl.oid_sr_wkfl
                                        and not tt_attr_pfvalue.tt_attrpfd_validate_result)
                           and c-application-mode <> "API"
                        then do:
       
                           yn = no.
                           /* The inventory is non-conforming, Continue? */
                           {us/bbi/pxmsg.i &MSGNUM=12459
                                           &ERRORLEVEL=2
                                           &CONFIRM=yn
                                           &CONFIRM-TYPE='LOGICAL'}
                           if not yn then do:
                              next-prompt location with frame a.
                              undo, retry.
                           end.
       
                        end. /* if can-find ld_det */
                     end. /* if transtype = "ISS-UNP" */
                     else if transtype = "RCT-UNP" then do:
                        {us/ca/cacratpr.i}
       
                        {us/px/pxrun.i &PROC       = 'createAttrpfValueRCT'
                                       &PROGRAM    = 'carcxr.p'
                                       &HANDLE     = ph_carcxr
                                       &PARAM      = "(input sr_wkfl.oid_sr_wkfl,
                                                       input pt_part,
                                                       input sr_wkfl.sr_site,
                                                       input sr_wkfl.sr_loc,
                                                       input sr_wkfl.sr_lotser,
                                                       input sr_wkfl.sr_ref,
                                                       input 'RCT-UNP',
                                                       input sr_wkfl.sr_qty,
                                                       input '',
                                                       input 0,
                                                       input table tt_attr_parameter by-reference,
                                                       input-output table tt_attr_pfvalue by-reference)"
                                       &NOAPPERROR = true
                                       &CATCHERROR = true
                        }
       
                        if lotserial_qty > 0
                           and can-find (first tt_attr_pfvalue
                           where tt_attr_pfvalue.tt_oid_attrpf_mstr
                           =sr_wkfl.oid_sr_wkfl ) then
                        do:
       
                           {us/ca/cainipf.i sr_wkfl.oid_sr_wkfl
                                            pt_part
                                            site
                                            location
                                            lotserial
                                            lotref
                                            d
                                            setd
                                            no
                           }
       
                           for first tt_attr_pfvalue no-lock
                              where tt_attr_pfvalue.tt_oid_attrpf_mstr = sr_wkfl.oid_sr_wkfl
                              and tt_attr_pfvalue.tt_attrpfd_ui_display:
       
                              if c-application-mode <> "API" then
                                 hide frame a no-pause.
      
                              if c-application-mode = "API"
                              then do:
                                 /* Call the API controller to set common buffer */
                                 run setCommonDataBuffer in ApiMethodHandle
                                    (input "ttLotItemAttribute").
                              end.

                              {us/bbi/gprun.i ""caatui.p""
                                 "(input sr_wkfl.oid_sr_wkfl,
                                   input pt_part,
                                   input sr_wkfl.sr_site,
                                   input sr_wkfl.sr_loc,
                                   input sr_wkfl.sr_lotser,
                                   input sr_wkfl.sr_ref,
                                   input sr_wkfl.sr_qty,
                                   input trans_um,
                                   input 'RCT-UNP',
                                   input-output table tt_attr_pfvalue by-reference)"}

                              if c-application-mode = "API"
                              then do:
                                 /* Call the API controller to clear buffer */
                                 run setCommonDataBuffer in ApiMethodHandle
                                    (input "").
                              end.
      
                              if c-application-mode <> "API" then
                                 view frame a.
                           end.
       
                        end. /* ELSE DO: */
                     end.
                  end.
       
       
               end. /* if not multi_entry */
       
            end. /* do on ... */
       
            /* DO NOT ACCESS UI WHEN PROCESSING API REQUEST */
            if c-application-mode <> "API" then do:
               display
                  total_lotserial_qty
                  "" @ total_amt
               with frame a.
            end. /* IF c-application-mode <> "API" */
       
            unit_cost = unit_cost * conv.
       
            run getGLDefaults.
            run getPurchaseAccountDefaults.
       
            l_unp_acct = yes.
            if issrct = "RCT" then do:
               assign
                  dr_acct = ""
                  dr_sub  = ""
                  dr_cc   = ""
                  dr_proj = ""
                  dr_desc = "".
       
               if transtype = "RCT-SOR" then do:
                  find first gl_ctrl where gl_domain = global_domain no-lock.
                  assign
                     cr_acct = gl_rtns_acct
                     cr_sub  = gl_rtns_sub
                     cr_cc   = gl_rtns_cc.
               end.
       
               else
               if transtype = "RCT-UNP" then do:
                  /* OUTPUT PARAMETER CR_SUB ADDED*/
                  {us/bbi/gprun.i ""icintr1.p""
                     "(input  transtype,
                       input  site,
                       output cr_acct,
                       output cr_sub,
                       output cr_cc,
                       output inv_mov,
                       output error-found)"}
                  if error-found then undo, retry.
                  if cr_acct = ""
                  then
                     assign
                        l_unp_acct = no
                        cr_acct    = dftPURAcct
                        cr_sub     = dftPURSubAcct
                        cr_cc      = dftPURCostCenter.
               end.
       
               else
               if transtype = "RCT-RS" then do:
       
                  find first ptp_det where ptp_domain = global_domain
                                       and ptp_part   = pt_part
                                       and ptp_site   = in_site
                  no-lock no-error.
       
                  if ((available ptp_det and ptp_iss_pol = no) or
                      (not available ptp_det 
                       and available pt_mstr and pt_iss_pol = no))
                  then do:
                     assign
                        cr_acct = dftFLRAcct
                        cr_sub  = dftFLRSubAcct
                        cr_cc   = dftFLRCostCenter.
                  end.
       
                  else do:
                     assign
                        cr_acct = dftCOPAcct
                        cr_sub  = dftCOPSubAcct
                        cr_cc   = dftCOPCostCenter.
                  end.
       
               end.
       
               find ac_mstr where ac_domain = global_domain and
                                  ac_code   = cr_acct
               no-lock no-error.
               if available ac_mstr then
                  cr_desc = ac_desc.
               else
                  cr_desc = "".
            end.
       
            else
            if issrct = "ISS" then do:
       
               assign
                  cr_acct = ""
                  cr_sub  = ""
                  cr_cc   = ""
                  cr_proj = ""
                  cr_desc = "".
       
               if transtype = "ISS-RV" or transtype = "ISS-PRV" then do:
                  assign
                     dr_acct = dftPURAcct
                     dr_sub  = dftPURSubAcct
                     dr_cc   = dftPURCostCenter.
               end.
       
               else
               if transtype = "ISS-UNP" then do:
       
                  /* OUTPUT PARAMETER DR_SUB ADDED*/
                  {us/bbi/gprun.i ""icintr1.p""
                     "(input  transtype,
                       input  site,
                       output dr_acct,
                       output dr_sub,
                       output dr_cc,
                       output inv_mov,
                       output error-found)"}
                  if error-found then undo, retry.
                  if dr_acct = "" then do:
       
                     find first ptp_det where ptp_domain = global_domain
                                          and ptp_part   = pt_part
                                          and ptp_site   = in_site
                     no-lock no-error.
       
                     if ((available ptp_det and ptp_iss_pol = no) or
                        (not available ptp_det
                         and available pt_mstr and pt_iss_pol = no))
                     then do:
                        assign
                           dr_acct = dftFLRAcct
                           dr_sub  = dftFLRSubAcct
                           dr_cc   = dftFLRCostCenter.
                     end.
                     else do:
                        assign
                           dr_acct = dftCOPAcct
                           dr_sub  = dftCOPSubAcct
                           dr_cc   = dftCOPCostCenter.
                     end.
       
                  end.
       
               end.
       
               find ac_mstr where ac_domain = global_domain and
                                  ac_code   = dr_acct
               no-lock no-error.
               if available ac_mstr then
                  dr_desc = ac_desc.
               else
                  dr_desc = "".
       
            end.
       
            /* DO NOT ACCESS UI WHEN PROCESSING API REQUEST */
            if c-application-mode <> "API" then do:
               display dr_desc cr_desc with frame a.
            end. /* IF c-application-mode <> "API" */
       
            if eff_date = ? then eff_date = today.
       
            seta:
            do on endkey undo mainloop, retry mainloop on error undo, retry
            with frame a:
                /* DO NOT RETRY IF PROCESSING API REQUEST */
               if retry and c-application-mode = "API"
                  then return error return-value.
       
               /*  IF THIS IS A BATCH RUN AND WE ARE DOING A RETRY, UNDO   */
               /*  AND LEAVE MAINLOOP (mfglef.i ERROR WAS INEFFECTIVE)     */
               {us/gp/gpcimex.i "mainloop"}
       
               /* clear work table records of LG and GL */
               {us/gp/gprunp.i "soldxr" "p" "clearWorkTableOfLGAndGL"}
       
               if c-application-mode <> "API" then
                  display unit_cost with frame a.
       
               if transtype = "RCT-UNP"
               then
                  assign
                     l_acct = cr_acct
                     l_sub  = cr_sub
                     l_cc   = cr_cc.
       
               else
               if transtype = "ISS-RV"
               or transtype = "ISS-PRV"
               then
                  assign
                     l_acct = dr_acct
                     l_sub  = dr_sub
                     l_cc   = dr_cc.
       
               if c-application-mode <> "API"
               then do:
                  display unit_cost
                  with frame a.
       
                  /* WHEN DOING SSM RESTOCKING, DON'T PROMPT FOR */
                  /* ORDER AND LINE */
                  if oidDosrDet <> 0 then
                     display
                     ordernbr
                     orderline
                     with frame a.
       
                  /* RETRIEVE SITES FOR GL RESTRICTION AND */
                  /* PASS TO AC_MSTR BROWSE */             
                  assign cCompanyList = "".
                  if multi_entry
                  then do:
                     for each sr_wkfl
                        where sr_domain = global_domain
                        and   sr_userid = SessionUniqueID
                        no-lock:
                        for first si_mstr where si_domain = global_domain and 
                                                si_site = sr_site no-lock:
                           if not can-do(cCompanyList, si_entity)
                           then do:
                              if cCompanyList = "" 
                              then 
                                 assign cCompanyList = si_entity.
                              else 
                                 assign 
                                    cCompanyList = cCompanyList + "," + si_entity.
                           end.
                        end. /* for first si_mstr */
                     end. /* for each sr_wkfl */
                  end. /* if multi_entry */
                  else do:
                     for first si_mstr where si_domain = global_domain and 
                                             si_site = site no-lock:
                        assign cCompanyList = si_entity.
                     end.
                  end.
       
                  /* Add the entity filter to ac_mstr browse */
                  {us/gp/gpbrparm.i &browse=gplu323.p 
                                    &parm=c-brparm1 &val="cCompanyList"} 
                  {us/gp/gpbrparm.i &browse=gplu323.p 
                                    &parm=c-brparm2 &val=''} 
                  /* Add the entity filter to cost center browse */
                  {us/gp/gpbrparm.i &browse=gplu600.p
                                    &parm=c-brparm1 &val="cCompanyList"}             
                  {us/gp/gpbrparm.i &browse=gplu600.p
                                    &parm=c-brparm2 &val=''}             
       
                  update
                     ordernbr  when (oidDosrDet = 0)
                     orderline when (oidDosrDet = 0)
                     so_job
                     traddr
                     rmks
                     eff_date when l_effdt
                     dr_acct when (issrct = "ISS")
                     dr_sub  when (issrct = "ISS")
                     dr_cc   when (issrct = "ISS")
                     dr_proj when (issrct = "ISS")
                     cr_acct when (issrct <> "ISS")
                     cr_sub  when (issrct <> "ISS")
                     cr_cc   when (issrct <> "ISS")
                     cr_proj when (issrct <> "ISS")
                  with frame a.
       
                  if eff_date = ?
                  then do:
                     eff_date = today.
                     display
                        eff_date
                        with frame a.
                  end. /*IF eff_date = ?*/
       
                  project = if issrct = "ISS"
                            then
                               dr_proj
                            else
                               cr_proj.
       
               end. /* IF c-application-mode <> "API" */
       
               else do: /* IF c-application-mode = "API" */
                  if lLegacyAPI then do:
                     assign
                        {us/mf/mfaiset.i ordernbr  ttInventoryTrans.nbr}
                        {us/mf/mfaiset.i orderline ttInventoryTrans.line}
                        {us/mf/mfaiset.i so_job    ttInventoryTrans.soJob}
                        {us/mf/mfaiset.i traddr    ttInventoryTrans.addr}
                        {us/mf/mfaiset.i rmks      ttInventoryTrans.rmks}
                        {us/mf/mfaiset.i eff_date  ttInventoryTrans.effdate}
                        {us/mf/mfaiset.i project   ttInventoryTrans.project}.
                     if issrct = "ISS" then
                        assign
                           {us/mf/mfaiset.i dr_acct ttInventoryTrans.drAcct}
                           {us/mf/mfaiset.i dr_sub  ttInventoryTrans.drSub}
                           {us/mf/mfaiset.i dr_cc   ttInventoryTrans.drCc}.
                     else
                        assign
                           {us/mf/mfaiset.i cr_acct ttInventoryTrans.crAcct}
                           {us/mf/mfaiset.i cr_sub  ttInventoryTrans.crSub}
                           {us/mf/mfaiset.i cr_cc     ttInventoryTrans.crCc}.
                  end.
                  else do:
                     assign
                        {us/mf/mfaistvl.i ordernbr    ttInvTrans.orderNbr}
                           when (oidDosrDet = 0)
                        {us/mf/mfaistvl.i orderline   ttInvTrans.orderLine}
                           when (oidDosrDet = 0)
                        {us/mf/mfaistvl.i so_job      ttInvTrans.soJob}
                        {us/mf/mfaistvl.i traddr      ttInvTrans.trAddr}
                        {us/mf/mfaistvl.i rmks        ttInvTrans.rmks}
                        {us/mf/mfaistvl.i eff_date    ttInvTrans.effDate}
                        {us/mf/mfaistvl.i dr_acct     ttInvTrans.drAcct}
                           when (issrct = "ISS")
                        {us/mf/mfaistvl.i dr_sub      ttInvTrans.drSub}
                           when (issrct = "ISS")
                        {us/mf/mfaistvl.i dr_cc       ttInvTrans.drCc}
                           when (issrct = "ISS")
                        {us/mf/mfaistvl.i dr_proj     ttInvTrans.drProj}
                           when (issrct = "ISS")
                        {us/mf/mfaistvl.i cr_acct     ttInvTrans.crAcct}
                           when (issrct <> "ISS")
                        {us/mf/mfaistvl.i cr_sub      ttInvTrans.crSub}
                           when (issrct <> "ISS")
                        {us/mf/mfaistvl.i cr_cc       ttInvTrans.crCc}
                           when (issrct <> "ISS")
                        {us/mf/mfaistvl.i cr_proj     ttInvTrans.crProj}
                           when (issrct <> "ISS").
                     assign project = if issrct = "ISS"
                                      then
                                         dr_proj
                                      else
                                         cr_proj.
                  end. /* IF NOT lLegacyAPI */
               end.
       
       
               /*QAD WMS DOES NOT SUPPORT LEGAL DOCUMENT */
               if not isProgInStack("whexprc.p") then do:
                  /* Address can't be blank for RCT-UNP */
                  if ((transtype = "RCT-UNP" and poc_fiscal_confirm) 
                      or transtype = "ISS-UNP")
                     and
                     can-find(im_mstr where im_domain = global_domain and
                                            im_inv_mov = inv_mov and
                                            im_flow <> 0)
                  then do:
                     if traddr = "" then do:
                        {us/bbi/pxmsg.i &MSGNUM=40 &ERRORLEVEL=3
                           &FIELDNAME=""ttInvTrans.trAddr""}
                        next-prompt traddr with frame a.
                        undo seta, retry seta.
                     end.
                     else if not can-find (ad_mstr 
                        where ad_domain = global_domain
                        and ad_addr = traddr) then do:
                        /* ADDRESS DOES NOT EXIST */
                        {us/bbi/pxmsg.i &MSGNUM=980 &ERRORLEVEL=3}
                        next-prompt traddr with frame a.
                        undo seta, retry seta.
                     end.
                  end. /* if traddr = "" and transtype = "RCT-UNP" ... */
               end.
       
               if traddr <> " " then do:
       
                  run getPurchaseAccountDefaults.
       
                  if transtype = "RCT-UNP" then do:
                     assign
                        cr_acct = if     l_acct     = cr_acct
                                     and l_unp_acct = no
                                  then
                                     dftPURAcct
                                  else
                                     cr_acct
                        cr_sub  = if     l_sub      = cr_sub
                                     and l_unp_acct = no
                                  then
                                     dftPURSubAcct
                                  else
                                     cr_sub
                        cr_cc   = if     l_cc       = cr_cc
                                     and l_unp_acct = no
                                  then
                                     dftPURCostCenter
                                  else
                                     cr_cc.
       
                     if c-application-mode <> "API" then
                        display
                           cr_acct
                           cr_sub
                           cr_cc
                        with frame a.
                  end.
       
                  else
                  if transtype = "ISS-RV" or transtype = "ISS-PRV"
                  then do:
                     assign
                        dr_acct = if l_acct = dr_acct
                                  then
                                     dftPURAcct
                                  else
                                     dr_acct
                        dr_sub  = if l_sub = dr_sub
                                  then
                                     dftPURSubAcct
                                  else
                                     dr_sub
                        dr_cc   = if l_cc = dr_cc
                                  then
                                     dftPURCostCenter
                                  else
                                     dr_cc.
                     if c-application-mode <> "API" then
                        display
                           dr_acct
                           dr_sub
                           dr_cc
                        with frame a.
                  end.
       
               end.
       
               /* CHECK EFFECTIVE DATE */
               find si_mstr where si_domain = global_domain and
                                  si_site   = site no-lock.
               {us/gp/gpglef1.i
                  &module = ""IC""
                  &entity = si_entity
                  &date = eff_date
                  &prompt = "eff_date"
                  &frame = "a"
                  &loop = "seta"}
               if l_using_supplier_consignment 
                  and (transtype = "RCT-UNP" or transtype = "ISS-UNP")
               then do:
       
                  for each sr_wkfl
                     where sr_domain = global_domain
                     and   sr_userid = SessionUniqueID
                  no-lock:
                     lotserial_qty = sr_qty * conv.
       
                     if issrct = "ISS" 
                     then 
                        lotserial_qty = - lotserial_qty.
       
                     {us/gp/gprunmo.i &program = ""pocnsix4.p"" 
                       &module  = "ACN"
                       &param   =  """(input part,
                                       input sr_site,
                                       input sr_loc,
                                       input right-trim(substring(sr_lotser,1,18)),
                                       input sr_ref,
                                       input (if lotserial_qty > 0 
                                              then 
                                                 true
                                              else 
                                                 false),
                                       output consign_flag)"""}
                     if consign_flag = true
                     then do:
                        /* DETERMINE COSTING METHOD */
                        {us/bbi/gprun.i ""csavg01.p""
                                        "(input  part,
                                          input  sr_site,
                                          output l_glx_set,
                                          output l_glx_mthd,
                                          output l_cur_set,
                                          output l_cur_mthd)"}
       
                        {us/gp/gprunp.i "gpscpl" "p" "getStatCurrWithInventory"
                                        "(input  mgmt_curr,
                                          input  lInventIsFallBack,
                                          input  lStatIsFallBack,
                                          input  eff_date,
                                          input  l_glx_mthd,
                                          output l_mgmt_acct_ex_rate1,
                                          output l_mgmt_acct_ex_rate2,
                                          output l_mgmt_curr_ex_rate1,
                                          output l_mgmt_curr_ex_rate2,
                                          output l_lStatCurrError,
                                          output l_iStatErrorMsg)"}
       
                        if l_lStatCurrError = true 
                        then do:
                           {us/bbi/pxmsg.i &MSGNUM=l_iStatErrorMsg 
                                           &ERRORLEVEL=4 &PAUSEAFTER=TRUE}
                           undo mainloop,retry mainloop.
                        end. /* IF l_lStatCurrError = TRUE */
                     end. /* IF consign_flag = TRUE */
                  end. /* FOR EACH sr_wkfl */
               end. /* IF l_using_supplier_consignment */
               /*VALIDATE ACCOUNTS*/
               find first gl_ctrl where gl_domain = global_domain 
                  no-lock no-error.
               if gl_verify then do with frame a:
       
                  if issrct = "ISS" then do:
       
                     if c-application-mode = "API" or
                        batchrun then do:
                        run verify-gl-accounts
                           (input dr_acct,
                            input dr_sub,
                            input dr_cc,
                            input project,
                            input "dr_acct",
                            output valid_acct).
                        if valid_acct = no then do:
                           if c-application-mode <> "API" then
                              next-prompt dr_acct with frame a.
                           undo mainloop, retry.
                        end.
                     end.
       
                     else do:
                        run verify-gl-accounts
                           (input dr_acct,
                            input dr_sub,
                            input dr_cc,
                            input project,
                            input "dr_acct",
                            output valid_acct).
                        if valid_acct = no then do:
                           if c-application-mode <> "API" then
                              next-prompt dr_acct with frame a.
                           undo, retry.
                        end.
                     end.
       
                  end. /* if issrct = "ISS" */
       
                  else do:
       
                     if c-application-mode = "API" or batchrun then do:
                        run verify-gl-accounts
                           (input cr_acct,
                           input cr_sub,
                           input cr_cc,
                           input project,
                           input "cr_acct",
                           output valid_acct).
                        if valid_acct = no then do:
                           if c-application-mode <> "API" then
                              next-prompt cr_acct with frame a.
                           undo mainloop, retry.
                        end.
                     end.
       
                     else do:
                        run verify-gl-accounts
                           (input cr_acct,
                            input cr_sub,
                            input cr_cc,
                            input project,
                            input "cr_acct",
                            output valid_acct).
                        if valid_acct = no then do:
                           if c-application-mode <> "API" then
                              next-prompt cr_acct with frame a.
                           undo, retry.
                        end.
                     end.
       
                  end. /* if issrct <> "ISS" */
       
               end. /* if gl_verify */
       
               /*QAD WMS DOES NOT SUPPORT LEGAL DOCUMENT */
               if not isProgInStack("whexprc.p") then do:
                  if transtype = "RCT-UNP" and
                     poc_fiscal_confirm and
                     can-find(im_mstr where im_domain = global_domain and
                                            im_inv_mov = inv_mov and
                                            im_flow <> 0)
                  then do:
                     pause 0.
                     if c-application-mode = "API" and not lLegacyAPI then do:
                        run getNextRecord in ApiMethodHandle (input "ttInvTransLD").
                        if return-value = {&RECORD-NOT-FOUND} then do:
                           undo seta, retry.
                        end.
                     end.
                        /*
                     subscribe to "getIssueLegalDocumentFlag" anywhere.
                     subscribe to "getLegalDocumentNumber" anywhere.
                     subscribe to "getLegalDocumentEffectDate" anywhere.
                     run fillLDInfo(input traddr, input site, yes, no).
                     unsubscribe to "getIssueLegalDocumentFlag".
                     unsubscribe to "getLegalDocumentNumber".
                     unsubscribe to "getLegalDocumentEffectDate".
                       */
                     l_create_shipper = issueld.
                     if return-value = {&APP-ERROR-RESULT}
                     then do:
                        if c-application-mode <> "API" then
                           hide frame rec-lgd.
                        undo seta, retry.
                     end.
                  end.
               end.
       
            end. /* seta */
       
            /* Check if Item, Site, Location & Account Combination */
            /* is restricted */
            if lookup(execname, "icunis.p,icunrc.p,icsorc.p,icrsrc.p") > 0
            then do:
       
               for each sr_wkfl
                  where sr_domain = global_domain
                    and sr_userid = SessionUniqueID
                    and sr_lineid = cline:
       
                  empty temp-table ttUpdateRestrictionSignature.
                  create ttUpdateRestrictionSignature.
       
                  assign
                     ttUpdateRestrictionSignature.category           = {&UNP}
                     ttUpdateRestrictionSignature.program            = execname
                     ttUpdateRestrictionSignature.part               = pt_part
                     ttUpdateRestrictionSignature.site               = sr_site
                     ttUpdateRestrictionSignature.siteTo             = ?
                     ttUpdateRestrictionSignature.location           = sr_loc
                     ttUpdateRestrictionSignature.locationTo            = ?
                     ttUpdateRestrictionSignature.inventoryStatus       = ?
                     ttUpdateRestrictionSignature.inventoryStatusTo     = ?
                     ttUpdateRestrictionSignature.changeInventoryStatus = no.
       
                  if lookup(execname, "icunrc.p,icsorc.p,icrsrc.p") > 0
                  then do:
                     assign
                        ttUpdateRestrictionSignature.account    = cr_acct
                        ttUpdateRestrictionSignature.subAccount = cr_sub
                        ttUpdateRestrictionSignature.costcenter = cr_cc
                        ttUpdateRestrictionSignature.project    = cr_proj.
                  end.
                  else
                  if lookup(execname, "icunis.p") > 0
                  then do:
                     assign
                        ttUpdateRestrictionSignature.account    = dr_acct
                        ttUpdateRestrictionSignature.subAccount = dr_sub
                        ttUpdateRestrictionSignature.costcenter = dr_cc
                        ttUpdateRestrictionSignature.project    = dr_proj.
                  end.
       
                  if isUpdateRestricted
                     (input table ttUpdateRestrictionSignature,
                      input yes)
                  then do:
                     undo setd, retry setd.
                  end. /* isUpdateRestricted */
       
               end. /*sr_wkfl */
            end.  /* if execname, "icunis.p, icunrc.p, icsorc.p, ... */
            /* Finish check if Item, Site, Loc & Acct Combination */
            /* is restricted */
       
       
            find ac_mstr no-lock
               where ac_mstr.ac_domain = global_domain
                 and ac_code = dr_acct no-error.
            if available ac_mstr then
               dr_desc = ac_desc.
            else
               dr_desc = "".
       
            find ac_mstr no-lock
               where ac_mstr.ac_domain = global_domain
                 and ac_code = cr_acct no-error.
            if available ac_mstr then
               cr_desc = ac_desc.
            else
               cr_desc = "".
       
            if c-application-mode <> "API" then
               display
                  dr_desc
                  cr_desc
               with frame a.
       
            total_amt = unit_cost * total_lotserial_qty.
            {us/bbi/gprun.i ""gpcurrnd.p""
               "(input-output total_amt, input gl_rnd_mthd)"}
       
            total_amt_fmt = total_amt:format.
            {us/bbi/gprun.i ""gpcurfmt.p""
               "(input-output total_amt_fmt, input gl_rnd_mthd)"}
       
            total_amt:format = total_amt_fmt.
       
            if c-application-mode <> "API" then
               display total_amt with frame a.
       
            i = 0.
            for each sr_wkfl no-lock
               where sr_wkfl.sr_domain = global_domain
                 and sr_userid = SessionUniqueID
                 and sr_lineid = cline:
               i = i + 1.
               if i > 1 then do:
                  leave.
               end.
            end.
       
            if (i > 1 or can-find(first tt_attr_pfvalue))
               and c-application-mode <> "API" then
            do on endkey undo mainloop, retry mainloop:
       
               yn = yes.
               /* DISPLAY LOTSERIALS BEING RECEIVED? */
               {us/bbi/pxmsg.i &MSGNUM=359 &ERRORLEVEL=1 &CONFIRM=yn}
       
               if yn then do:
       
                  hide frame a.
       
                  form
                     pt_part
                  with frame b side-labels width 80.
       
                  /* SET EXTERNAL LABELS */
                  setFrameLabels(frame b:handle).
       
                  display pt_part with frame b.
       
                  for each sr_wkfl no-lock
                     where sr_wkfl.sr_domain = global_domain
                      and  sr_userid = SessionUniqueID
                  with frame f-a width 80:
       
                     /* SET EXTERNAL LABELS */
                     setFrameLabels(frame f-a:handle).
       
                     /* Check Result against attribute specification */
                     if transtype = "ISS-UNP"
                        or (transtype = "RCT-UNP" and sr_wkfl.sr_qty < 0) then do:
                        {us/px/pxrun.i &PROC      ='validateAttrSpecStopOnNonConform'
                                       &PROGRAM   ='caisxr.p'
                                       &HANDLE    = ph_caisxr
                                       &PARAM     ="(input sr_wkfl.oid_sr_wkfl,
                                                     input-output table tt_attr_pfvalue by-reference)"
                                       &NOAPPERROR=true
                                       &CATCHERROR=true
                        }
                     end.
                     else if transtype = "RCT-UNP" then do:
                        {us/px/pxrun.i &PROC      ='validateAttrSpecStopOnNonConform'
                                       &PROGRAM   ='caatdxr.p'
                                       &HANDLE    = ph_caatdxr
                                       &PARAM     ="(input sr_wkfl.oid_sr_wkfl,
                                                     input-output table tt_attr_pfvalue by-reference)"
                                       &NOAPPERROR=true
                                       &CATCHERROR=true
                        }
                     end.
       
                     validationPass = "".
                     find first tt_attr_pfvalue
                        where tt_attr_pfvalue.tt_oid_attrpf_mstr = sr_wkfl.oid_sr_wkfl
                     no-lock no-error.
       
                     if available tt_attr_pfvalue then do:
                        if can-find (first tt_attr_pfvalue
                                     where tt_attr_pfvalue.tt_oid_attrpf_mstr = sr_wkfl.oid_sr_wkfl
                                     and tt_attr_pfvalue.tt_attrpfd_validate_result = no)
                        then do:
                           validationPass = getTermLabelRt('NON-CONFORMING',14).
                        end.
                        else do:
                           validationPass = getTermLabelRt('CONFORMING', 14).
                        end.
                     end.
       
       
                     display
                        sr_site
                        sr_loc
                        sr_lotser
                        sr_ref  format "x(8)" column-label "Ref"
                        sr_qty
                     with frame f-a.
       
                     if validationPass <> "" then do:
                        display
                           validationPass no-label
                        with frame f-a.
                     end. /* if validationPass <> "" */
       
                     {us/gp/gpwait.i &INSIDELOOP=YES &FRAMENAME=f-a}
       
                  end.
       
                  {us/gp/gpwait.i &OUTSIDELOOP=YES}
       
               end.
       
            end.
       
            assign
               shipnbr = ""
               ship_date = ?.
       
            /* Pop-up to collect shipment information */
            if transtype = "RCT-UNP" or
               transtype = "RCT-SOR" or
               transtype = "RCT-RS"
            then do:
       
               ship_date = eff_date.
       
               if shc_ship_rcpt then do:
                  pause 0.
       
                  /* IF TRANSACTION IS RCT-SOR OR RCT_RS THEN WE NEED TO */
                  /* ALLOW ENTRY FOR INVENTORY MOVEMENT CODE             */
                  if transtype <> "RCT-UNP"
                  then
                     inv_mov = "".

                  if c-application-mode = "API" and not lLegacyAPI then do:
                     run setCommonDataBuffer in ApiMethodHandle
                        (input "ttShipmentInfo").
                  end. /* c-application-mode = "API" */

                  {us/bbi/gprun.i ""icshup.p""
                     "(input-output shipnbr,
                       input-output ship_date,
                       input-output inv_mov,
                       input transtype, yes,
                       input 10,
                       input 20,
                       input site)"}

                  if c-application-mode = "API" and not lLegacyAPI then do:
                     run setCommonDataBuffer in ApiMethodHandle(input "").
                  end. /* c-application-mode = "API" */

               end. /* if shc_ship_rcpt */
       
            end. /* if transtype = "RCT-UNP" or ... */
       
            do on endkey undo mainloop, retry mainloop:
       
               if c-application-mode = "API" and not lLegacyAPI and retry then
                  next mainloop.
       
               /* CHECK TO SEE IF CONSIGNMENT IS ACTIVE */
               {us/bbi/gprun.i ""gpmfc01.p""
                    "(input ENABLE_CUSTOMER_CONSIGNMENT,
                      input 10,
                      input ADG,
                      input CUST_CONSIGN_CTRL_TABLE,
                      output using_cust_consignment)"}
       
               if using_cust_consignment and
                  ((transtype = "ISS-UNP"  and lotserial_qty < 0) or
                   (transtype = "RCT-UNP"  and lotserial_qty > 0)) and
                  ordernbr    <> "" and
                  lotserial_qty <> 0
               then do:
       
                  /*Check sales order to see if it is consigned and      */
                  /* that the transfer item matches the sales order item*/
                  run checkConsignedOrder
                     (input ordernbr,
                      input orderline,
                      input pt_part,
                      output consigned_line,
                      output error-found).
       
                  if error-found then do:
                     /* MATCHING ORDER LINE ITEM FOR THIS PART NOT FOUND*/
                     {us/bbi/pxmsg.i &MSGNUM=8285 &ERRORLEVEL=3}
                       next setd.
                  end.
       
               end. /*if using_cust_consignment*/
       
               if using_cust_consignment and
                  ((transtype = "ISS-UNP"  and lotserial_qty > 0) or
                   (transtype = "RCT-UNP"  and lotserial_qty < 0)) and
                  lotserial_qty <> 0
               then do:
       
                  run checkConsignmentInventory
                     (input ordernbr,
                      input orderline,
                      input site,
                      input pt_part,
                      input location,
                      input lotserial,
                      input lotref,
                      input lotserial_qty * trans_conv,
                      output error-found).
       
                  if error-found
                     then do:
                     /* UNABLE TO ISSUE/RECEIVE CONSIGNED INVENTORY*/
                     {us/bbi/pxmsg.i &MSGNUM=4937 &ERRORLEVEL=3}
                     next setd.
                  end.
       
               end. /*if using_cust_consignment*/
       
               yn = yes.
               
               /* GY01 POPUP-MENU CIP */
               cipid-loop:
               do on error undo, retry:
               if can-find(first code_mstr where code_domain = global_domain
                                             and code_fldname = "xxcip"
                                             and code_value begins "glcode"
                                             and (code_cmmt = dr_acct
                                             or code_cmmt = cr_acct) no-lock)
                                             then 
               do:
                      update cipid with frame cip.
                      find xxcip_mstr where xxcip_mstr.xxcip_domain = global_domain 
                                        and xxcip_mstr.xxcip_cipid = cipid
                                        no-lock no-error.
                      if available xxcip_mstr then 
                      do:
                      assign cipdesc = xxcip_mstr.xxcip_cipdesc.
                      disp cipdesc .
                      end.
                      else
                      do:
                        /* CIPID NOT exist */
                       {us/bbi/pxmsg.i &MSGNUM = 9001 &ERRORLEVEL = 3}
                       
                       if c-application-mode <> "API" then do:
                          next-prompt cipid with frame cip.
                          undo, retry cipid-loop.
                       end.

                      end.                      
               
               end.
               
               end. /* do on error undo, retry: */
                              
       
               if c-application-mode <> "API" then do:
                  /* IS ALL INFO CORRECT? */
                  {us/bbi/pxmsg.i &MSGNUM=12 &ERRORLEVEL=1 &CONFIRM=yn}
               end.
       
               /* ADDED SECTION TO DO FINAL ISSUE CHECK */
               if yn then do:
       
                  release ld_det.
       
                  {us/ic/icintr2.i "sr_userid = SessionUniqueID"
                     transtype
                     pt_part
                     trans_um
                     error-found
                     """"}
       
                  if error-found then do:
                     /* UNABLE TO ISSUE OR RECEIVE FOR ITEM*/
                     {us/bbi/pxmsg.i &MSGNUM=161 &ERRORLEVEL=3 &MSGARG1=part}
                     next setd.
                  end.
       
                  leave setd.
       
               end.
               if c-application-mode = "API" then leave setd.
            end.
       
         end. /*setd*/
       
         for each qad_wkfl exclusive-lock where 
           qad_wkfl.qad_domain = SessionUniqueID and
           qad_wkfl.qad_key1 = "UpdateHistTransactions" and
           qad_wkfl.qad_key2 = "LegalDocumentIDs":
           delete qad_wkfl. 
         end.
         if poc_fiscal_confirm and
            transtype = "RCT-UNP" then do:
            for first lgd_mstr no-lock where
               lgd_mstr.oid_lgd_mstr = lgdkey:
       
               create qad_wkfl.
               assign
                  qad_wkfl.qad_domain = SessionUniqueID
                  qad_wkfl.qad_key1 = "UpdateHistTransactions"
                  qad_wkfl.qad_key2 = "LegalDocumentIDs"
                  qad_wkfl.qad_decfld[1] = lgdkey
                  qad_wkfl.qad_charfld[1] = lgd_nbr.
            end.
         end.  
       
         if c-application-mode = "API" and not lLegacyAPI then do:
            run setCommonDataBuffer in ApiMethodHandle
               (input "ttCommonShipperInfo").
         end. /* c-application-mode = "API" */
       
         /* FOURTH PARAMETER IS KANBAN ID - NOT USED HERE SO PASS AS 0     */
         {us/bbi/gprun.i ""icintra.p"" 
                          "(shipnbr, ship_date, inv_mov, 0, l_create_shipper,
                            input-output table tt_attr_pfvalue by-reference)" }
       
         if c-application-mode = "API" and not lLegacyAPI then do:
            run setCommonDataBuffer in ApiMethodHandle (input "").
         end. /* c-application-mode = "API" */
       
         /* Clear the records in work table for unconfirm shipper flag. */
         {us/gp/gprunp.i "soldxr" "p" "clearWorkTableOfUnConfirmSh"}
       
         /*QAD WMS DOES NOT SUPPORT LEGAL DOCUMENT */
         if not isProgInStack("whexprc.p") then do:
            if poc_fiscal_confirm and
               transtype = "RCT-UNP"
            then do:
               run bindTRHist(input lgdkey, input tr_recno, input 0).
               run clearEmptyLD(input lgdkey, no).
       
               for first tr_hist where recid(tr_hist) = tr_recno
               no-lock:
                  {us/px/pxrun.i &PROC = 'updateFiscalLine'
                     &PROGRAM = 'gpldxr.p'
                     &handle  = ph_gpldxr
                     &PARAM   = "(input lgdkey,
                                  input ""4"", /* 4 - Unplanned Receipt */
                                  input tr_trnbr)"
                     &NOAPPERROR = true
                     &CATCHERROR = true}
               end.
               for each qad_wkfl exclusive-lock where 
                  qad_wkfl.qad_domain = SessionUniqueID and
                  qad_wkfl.qad_key1 = "UpdateHistTransactions" and
                  qad_wkfl.qad_key2 = "LegalDocumentIDs":
                  delete qad_wkfl. 
               end.
       
            end.
         end.
       
         /* update legal document number in General Ledger */
         /* Unposted Transaction */
         /* Detail table. */
         {us/gp/gprunp.i "soldxr" "p" "updateLegalNumToUnpostedGL"}   
       
         if c-application-mode = "API" and lLegacyAPI then leave.
       
         if restockingDone then leave.
         if c-application-mode <> "API" then
            hide frame b.

         leave skipBlock. /* NO CTRL-C PROCESSING */

      end. /* updateBlock */

      /* DELETE THE lotw_wkfl RECORDS IF USER DOES CTRL + C */
      {us/bbi/gprun.i ""gplotwdl.p""}

      /* EXECUTE CTRL-C AGAIN */
      stop.

   end. /* skipBlock */

end. /* mainloop */
 
if c-application-mode = "API" then do:
   /* disallow API to call attribute code */
   {us/px/pxrun.i &PROC       = 'disallowApiCall'
                  &PROGRAM    = 'caexatxr.p'
                  &HANDLE     = ph_caexatxr
                  &NOAPPERROR = true
                  &CATCHERROR = true
   }
end. /* if c-application-mode = "API" */

delete procedure hUpdateRestrictedLibrary no-error.
 
if c-application-mode = "API" then return {&SUCCESS-RESULT}.
 
PROCEDURE verify-gl-accounts:
   /* THIS SUBROUTINE DETERMINES THE VALIDITY OF THE ACCOUNT, SUB-    */
   /* ACCOUNT, COST CENTER AND PROJECT  USING THE PERSISTENT          */
   /* PROCEDURES.                                                     */
   define input  parameter acct        like trgl_dr_acct no-undo.
   define input  parameter sub         like trgl_dr_sub  no-undo.
   define input  parameter cc          like trgl_dr_cc   no-undo.
   define input  parameter proj        like wo_proj      no-undo.
   define input  parameter acctfldname like trgl_dr_acct no-undo.
   define output parameter glvalid     like mfc_logical initial true no-undo.
 
   /* INITIALIZE SETTINGS */
   {us/gp/gprunp.i "gpglvpl" "p" "initialize"}
 
   /* SET CONTROL FOR CHEKCING ACCOUNT GLTYPE/GLSYSTEMTYPE */
   {us/gp/gprunp.i "gpglvpl" "p" "set_acct_gltype_ver" "(input true)"}
   /* SET ENTITY VERIFICATION TO YES */
   if not can-find (first sr_wkfl
   where sr_domain = global_domain
   and   sr_userid = SessionUniqueID ) then
   do:
      find first si_mstr where si_domain = global_domain 
                           and si_site = site no-lock no-error.
      if available si_mstr then
      do:
         {us/gp/gprunp.i "gpglvpl" "p" "set_coa_restriction_ver" "(input true, input si_entity)"}
      end.
      else do:
         {us/gp/gprunp.i "gpglvpl" "p" "set_coa_restriction_ver" "(input true, input """")"}
      end.
   end.
   else do:
      {us/gp/gprunp.i "gpglvpl" "p" "set_coa_restriction_ver" "(input true, input """")"}
      /* PREPARE ENTITY LIST */
      for each sr_wkfl
      where sr_domain = global_domain
      and   sr_userid = SessionUniqueID no-lock:
         find first si_mstr where si_domain = global_domain 
                              and si_site = sr_site no-lock no-error.
         if available si_mstr then 
         do: 
            {us/gp/gprunp.i "gpglvpl" "p" "prepareEntitiesForCyExcl"
               "(input acct,
                 input sub,
                 input cc,
                 input proj,
                 input si_entity)"}
         end.
      end. /* for each sr_wkfl */
   end. /* else do */
   /* AP_ACCT/SUB/CC VALIDATION */
   {us/gp/gprunp.i "gpglvpl" "p" "validate_fullcode"
      "(input acct,
        input sub,
        input cc,
        input proj,
        input acctfldname,
        output glvalid)"}
 
END PROCEDURE.
 
PROCEDURE getGLDefaults:
   /* FIND DEFAULT FOR COST OF PRODUCTION ACCT */
 
   {us/bbi/gprun.i ""glactdft.p""
      "(input ""WO_COP_ACCT"",
        input pt_mstr.pt_prod_line,
        input if available in_mstr then in_mstr.in_site
                                   else site,
        input """",
        input """",
        input no,
        output dftCOPAcct,
        output dftCOPSubAcct,
        output dftCOPCostCenter)"}
 
   /* FIND DEFAULT FOR FLOOR STOCK ACCT */
   {us/bbi/gprun.i ""glactdft.p""
      "(input ""WO_FLR_ACCT"",
        input pt_mstr.pt_prod_line,
        input if available in_mstr then in_mstr.in_site
                                   else site,
        input """",
        input """",
        input no,
        output dftFLRAcct,
        output dftFLRSubAcct,
        output dftFLRCostCenter)"}
 
END PROCEDURE.
 
PROCEDURE getPurchaseAccountDefaults:
 
   /* Find default for purchases acct */
   for first vd_mstr
       where vd_mstr.vd_domain = global_domain
         and vd_addr = traddr
   no-lock: end.
 
   {us/bbi/gprun.i ""glactdft.p""
      "(input ""PO_PUR_ACCT"",
        input pt_mstr.pt_prod_line,
        input if available in_mstr then in_mstr.in_site
                                   else site,
        input if available vd_mstr then vd_type
                                   else """",
        input """",
        input no,
        output dftPURAcct,
        output dftPURSubAcct,
        output dftPURCostCenter)"}
 
END PROCEDURE.
 
PROCEDURE checkConsignmentInventory:
 
   define input  parameter ip_ordernbr    as character no-undo.
   define input  parameter ip_orderline   as character no-undo.
   define input  parameter ip_site        like ld_site no-undo.
   define input  parameter ip_part        like ld_part no-undo.
   define input  parameter ip_location    like ld_loc  no-undo.
   define input  parameter ip_lotser      like ld_lot  no-undo.
   define input  parameter ip_ref         like ld_ref  no-undo.
   define input  parameter ip_tran_qty    as decimal   no-undo.
   define output parameter op_error      as logical   no-undo.
 
   define variable consigned_line        as logical   no-undo.
   define variable unconsigned_qty       as decimal   no-undo.
   define variable consigned_qty_oh      as decimal   no-undo.
   define variable location_qty          as decimal   no-undo.
   define variable procid                as character no-undo.
 
   /*IF A SALES ORDER WAS ENTERED, CHECK WHETHER IT IS FOR A   */
   /*CONSIGNED ITEM.                                           */
 
   if ip_ordernbr <> "" then do:
      run checkConsignedOrder
         (input ip_ordernbr,
          input ip_orderline,
          input ip_part,
          output consigned_line,
          output op_error).
      if consigned_line then
         op_error = yes.
      else
         op_error = no.
   end.
 
   if not op_error then do:
      /*IF CONSIGNED, FIND OUT HOW MUCH NON-CONSIGNED INVENTORY   */
      /*IS AT THE LOCATION. IF THERE IS NOT ENOUGH TO COVER THE   */
      /*QTY BEING ISSUED, THEN ERROR.                             */
 
      /*RETRIEVE THE TOTAL QTY ON-HAND FOR THE LOCATION */
      for first ld_det
           where ld_domain = global_domain and
                 ld_part = ip_part     and
                 ld_site = ip_site     and
                 ld_loc  = ip_location and
                 ld_lot  = ip_lotser   and
                 ld_ref  = ip_ref
      no-lock:
         assign
             location_qty  = ld_qty_oh
             consigned_qty_oh = ld_cust_consign_qty.
 
      end. /*for first ld_det*/
 
      unconsigned_qty = location_qty - consigned_qty_oh.
 
      if (consigned_qty_oh <> 0) and
         ((ip_tran_qty > 0 and unconsigned_qty < ip_tran_qty) or
          (ip_tran_qty < 0 and unconsigned_qty < (ip_tran_qty * -1)))
      then
        op_error = yes.
 
   end.
 
END PROCEDURE. /*checkConsignmentInventory*/
 
PROCEDURE checkConsignedOrder:
   define input parameter ip_ordernbr    as character no-undo.
   define input parameter ip_orderline   as character no-undo.
   define input parameter ip_part        as character no-undo.
   define output parameter op_consigned  as logical   no-undo.
   define output parameter op_error      as logical   no-undo.
 
   op_consigned = no.
 
   {us/gp/gprunmo.i
      &program = "socnsod1.p"
      &module = "ACN"
      &param = """(input ip_ordernbr,
                   input ip_orderline,
                   output op_consigned,
                   output consign_loc,
                   output intrans_loc,
                   output max_aging_days,
                   output auto_replenish)"""}
 
   if op_consigned then do:
      if can-find(first sod_det where
                        sod_domain = global_domain and
                        sod_nbr = ordernbr and
                        sod_line = orderline and
                        sod_part = ip_part and
                        sod_compl_stat = "")
      then
         op_error = no.
      else
         op_error = yes.
   end. /* IF op_consigned */
 
END PROCEDURE. /*checkConsignedOrder*/
 
PROCEDURE defaultDepotOrderRestock:
 
   /* IF THE CALLING PROGRAM IS fsdorstk.p THEN WE oidDosrDet WILL BE SET */
   /* READ oidDosrDet HERE IF THERE IS SOME VALUE THEN DEFAULT SOME DATA */
   /* OTHERWISE CONTINUE TO DO PROMPT WITHOUT DEFAULT. */
   /* icintr.p IS CALLED BY 6 OTHER MENU PROGRAM AND DID NOT WANT TO */
   /* IMPACT THEM, THAT IS WHY THIS PERSISTANCE PROCEDURE IS USED TO GET/SET */
   {us/px/pxrun.i &PROC  = 'getOidDosrDet' &PROGRAM = 'fssmxr.p'
            &HANDLE=ph_fssmxr
            &PARAM = "(output oidDosrDet)"
            &NOAPPERROR = true
            &CATCHERROR = true
   }
   if oidDosrDet <> 0 then do:
 
      for first dosr_det where dosr_domain = global_domain
                         and   oid_dosr_det = oidDosrDet
      no-lock: end.
 
      for first itm_det where itm_domain = global_domain
                        and   itm_nbr    = dosr_itm_nbr
                        and   itm_prefix = "CA"
                        and   itm_type   = ""
                        and   itm_line   = dosr_itm_line
                        and   itm_itm_line = 0
      no-lock: end.
 
      /* USE ALTERNATE ITEM WHILE RESTOCKING */
      for first pt_mstr where pt_domain = global_domain
                        and   pt_part   = itm_alternate
      no-lock: end.
 
      if c-application-mode <> "API" then
         display
            pt_part
            pt_lot_ser
            pt_um
            pt_desc1
            pt_desc2
         with frame a.
 
      assign
         restockingDone = yes /* TO STOP THE REPEAT LOOP */
         lotserial_qty  = dosr_qty
         site           = dosr_site
         location       = dosr_loc
         lotserial      = dosr_serial
         ordernbr       = itm_nbr
         orderline      = itm_line.
   end. /* if oidDosrDet <> 0 */
END PROCEDURE. /* defaultDepotOrderReceipt */
 
PROCEDURE itemAttributeUIPrompt:
   define input parameter ipDisplayAttributeUI  as logical   no-undo.
 
   if c-application-mode <> "API" then do:
      if ipDisplayAttributeUI = yes
      then do:
         hide frame a no-pause.
      end.
      else do:
        view frame a.
      end.
   end. /* if c-application-mode <> "API" */
END PROCEDURE. /* itemAttributeUIPrompt */
/*
PROCEDURE getIssueLegalDocumentFlag:
   define output parameter opIssueLd as logical no-undo.

   if available ttInvTransLD then
      opIssueLd = ttInvTransLD.issueLD.

END PROCEDURE.  /* PROCEDURE getIssueLegalDocumentFlag */

PROCEDURE getLegalDocumentNumber:
   define output parameter opLgdNbr as character no-undo.

   if available ttInvTransLD then
      opLgdNbr = ttInvTransLD.lgdNbr.

END PROCEDURE.  /* PROCEDURE getLegalDocumentNumber */

PROCEDURE getLegalDocumentEffectDate:
   define output parameter opEffDate as date no-undo.

   if available ttInvTransLD then
      opEffDate = ttInvTransLD.effDate.

END PROCEDURE.  /* PROCEDURE getLegalDocumentEffectDate */
*/